<?php

class Application_Model_Course extends Ahs_Model
{

    /**
     * @var integer
     */
    protected $_id;
    /**
     * @var string
     */
    protected $_name;
    /**
     * @var string
     */
    protected $_image;
    /**
     * @var string
     */
    protected $_description;
    /**
     * @var datetime
     */
    protected $_creationdate;
    /**
     * @var datetime
     */
    protected $_modifieddate;
    /**
     * @var datetime
     */
    protected $_deleteddate;
    /**
     * @var array
     */
    protected $_announcements;
    /**
     * @var int
     */
    protected $_author_id;
    
    
    /**
     * @return integer
     */    
    public function getId() {
        return $this->_id;
    }
    /**
     * @param integer $id
     */
    public function setId($id){
        $this->_id = $id;
    }
    
    /**
     * @return string
     */
    public function getName() {
        return $this->_name;
    }
    /**
     * @param string $name
     */
    public function setName($name) {
        $this->_name = $name;
    }
    
    /**
     * @return string
     */
    public function getImage() {
        return $this->_image;
    }
    /**
     * @param string $image
     */
    public function setImage($image) {
        $this->_image = $image;
    }
    
    /**
     * @return string
     */
    public function getDescription() {
        return $this->_description;
    }
    /**
     * @param string $description
     */
    public function setDescription($description) {
        $this->_description = $description;
    }
    
    /**
     * @return datetime
     */
    public function getCreationDate() {
        return $this->_creationdate;
    }
    /**
     * @param datetime $date
     */
    public function setCreationDate($date) {
        $this->_creationdate = $date;
    }
    
    /**
     * @return datetime
     */
    public function getModifiedDate() {
        return $this->_modifieddate;
    }
    /**
     * @param datetime $date
     */
    public function setModifiedDate($date) {
       return $this->_deleteddate;
    }
    
    /**
     * @param datetime $date
     */
    public function setDeletedDate($date) {
        $this->_deleteddate = $date;
    }
    /**
     * @return datetime
     */
    public function getDeletedDate() {
        return $this->_deleteddate;
    }

    /**
     * @return Array(Application_Model_Announcement)
     */
    public function getAnnouncements()
    {
        if($this->_announcements == null && $this->_id != null)
        {
            // Get announcements
            $mapperAnnouncements    = new Application_Model_AnnouncementMapper();
            $this->setAnnouncements($mapperAnnouncements->fetchByCourseId($this->Id));
        }
        
        return $this->_announcements;
    }
    /**
     * @param Array(Application_Model_Announcement) $announcements
     */
    public function setAnnouncements($announcements) {
        $this->_announcements = $announcements;
    }
    /**
     * Get the total number of announcements
     * @return integer
     */
    private $_announcement_count;
    public function getCountAnnouncements()
    {
        if($this->_announcement_count == null && $this->_id != null)
        {
            $mapper    = new Application_Model_AnnouncementMapper();
            $this->setCountAnnouncements($mapper->getCountByCourseId($this->_id));
        }
        
        return $this->_announcement_count;
    }
    public function setCountAnnouncements($count)
    {
        $this->_announcement_count = $count;
    }
    
    /**
     * @return Array(Application_Model_Book)
     */
    public function getBooks()
    {
        if($this->_id != null)
        {
            // Get books
            $mapper = new Application_Model_BookMapper();
            return $mapper->fetchByCourseId($this->Id);
        }
        
        return null;
    }
    /**
     * Get the total number of books
     * @return integer
     */
    private $_book_count;
    public function getCountBooks()
    {
        if($this->_book_count == null && $this->_id != null)
        {
            $mapper    = new Application_Model_BookMapper();
            $this->setCountBooks($mapper->getCountByCourseId($this->_id));
        }
        
        return $this->_book_count;
    }
    public function setCountBooks($count)
    {
        $this->_book_count = $count;
    }
    
    /**
     * @return integer
     */    
    public function getAuthorId() {
        return $this->_author_id;
    }
    /**
     * @param integer $authorId
     */
    public function setAuthorId($author_id) {
        $this->_author_id = $author_id;
    }
    /**
     * Get the author object
     * @return Application_Model_User
     */
    public function getAuthor()
    {
        if($this->_author_id == null)
        {
            // Get author
            $mapper = new Application_Model_UserMapper();
            return $mapper->fetchById($this->AuthorId);
        }
        
        return null;
    }
    
    /**
     * Get the number of followers
     */
    public $_followercount;
    public function getCountFollowers()
    {
        if($this->_followercount == null && $this->_id != null)
        {
            $mapper    = new Application_Model_UserMapper();
            $this->setCountFollowers($mapper->getCountByCourseId($this->_id));
        }
        
        return $this->_followercount;
    }
    public function setCountFollowers($count)
    {
        $this->_followercount = $count;
    }
}

